<!DOCTYPE html>
<html>

<body>

    <p>Count numbers:
        <output id="result"></output>
    </p>
    <button onclick="startWorker()">Start Worker</button>
    <button onclick="stopWorker()">Stop Worker</button>
    <button onclick="windowOpen()">打开一个网页</button>
    <br />
    <br />

    <script>
        var w;
        function startWorker() {
            if (typeof (Worker) !== "undefined") {
                // if (typeof (w) == "undefined") {
                    w = new Worker("webworkers.js");
                // }
                console.log(w)
                w.onmessage = function (event) {
                    console.log(event)
                    document.getElementById("result").innerHTML = event.data;
                };
            } else {
                document.getElementById("result").innerHTML = "Sorry, your browser does not support Web Workers...";
            }
        }

        function stopWorker() {
            w.terminate();
            console.log(w)
        }
        function windowOpen() { 
            window.open('//www.hao123.com')
        }
    </script>

</body>

</html>